home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000089_icon-group-sender_Mon Oct 23 12:24:29 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9NJNtE26724
  4.     for icon-group-addresses; Mon, 23 Oct 2000 12:23:55 -0700 (MST)
  5. Message-Id: <200010231923.e9NJNtE26724@baskerville.CS.Arizona.EDU>
  6. Delivered-To: fixup-icon-group@CS.Arizona.EDU@fixme
  7. From: Cheyenne Wills <cheyenne_wills@uswest.net>
  8. To: icon-group@cs.arizona.edu
  9. Subject: Re: How to "declare" a string?
  10. Date: Mon, 23 Oct 2000 10:59:15 +0100 (MDT)
  11. X-Mailerorigin: http://www.fsai.fh-trier.de/~schmitzj/Xclasses/XCmail/
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14. Content-Length: 1196
  15.  
  16. Icon handles datatyping differently then languages such as C, or Java. 
  17. Icon will try to convert the datatype to the apporiate type needed by the
  18. current operation.
  19.  
  20. For example:
  21.  
  22. some_number := 1234
  23. a_string = "this is a string"
  24.  
  25. new_number := some_number + 5  # -> 1239
  26. new_string := a_string || "."  # -> "this is a string."
  27.  
  28. another_string := "4" || "2"   # -> "42"
  29. some_fun := another_string + 3 # -> 45
  30. more_fun := a_string || some_number # -> "this is a string1234"
  31.  
  32. Also one does not need to "declare" variables before using them.  They all
  33. have a default value of &null.  What this means is that as long as the
  34. first time the variable is used in a expression it is either "recieving a
  35. value" or it is tested for null.
  36.  
  37. For example:
  38.  
  39. procedure main()
  40.    repeat {
  41.       if /count then count := 5   # First checks to see of varable is null
  42.       if count > 10 then break
  43.       count := count + 2
  44.    }
  45. end
  46.  
  47. This can be rewritten as:
  48.  
  49. procedure main()
  50.     repeat {
  51.         /count := 5
  52.         (10 >= count) +:= 2
  53.     }
  54. end
  55.  
  56. The above relies on two features of Icon, one the behavior of failure
  57. within expressions and the fact that an expression can return (produce) a
  58. "variable"
  59.  
  60. Cheyenne
  61.  
  62.  
  63.